#!/bin/sh
################################################################################
# video
#
# The script configures the video.
################################################################################
. /etc/rc.d/functions

start() {

    local hostname

    /bin/touch /var/lib/init/video.inprogress

    /usr/bin/logger -s -t minimyth -p "local0.info" "[init.d/video] Starting..."

    #Set MythTV video playback profile (if enabled by MM_VIDEO_PLAYBACK_PROFILE="auto")
    if [ -n "${MM_VIDEO_PLAYBACK_PROFILE}" ] ; then

        if [ "x${MM_VIDEO_PLAYBACK_PROFILE}" = "xauto" ] ; then

            case "${MM_X_HW_TYPE}" in
                nvidia_vdpau)
                    /usr/bin/logger -t minimyth -p "local0.info" "[init.d/video] Nvidia HW Accell. detected: auto-selecting DefaultVideoPlaybackProfile to \"VDPAU Normal\""
                    mm_mythdb_settings_set DefaultVideoPlaybackProfile "VDPAU Normal"
                    ;;
                nvidia_legacy_vdpau)
                    /usr/bin/logger -t minimyth -p "local0.info" "[init.d/video] Nvidia legacy HW Accell. detected: auto-selecting DefaultVideoPlaybackProfile to \"VDPAU Normal\""
                    mm_mythdb_settings_set DefaultVideoPlaybackProfile "VDPAU Normal"
                    ;;
                radeon_vdpau)
                    /usr/bin/logger -t minimyth -p "local0.info" "[init.d/video] Radeon HW Accell. detected: auto-selecting DefaultVideoPlaybackProfile to \"VDPAU Normal\""
                    mm_mythdb_settings_set DefaultVideoPlaybackProfile "VDPAU Normal"
                    ;;
                radeon_vaapi)
                    /usr/bin/logger -t minimyth -p "local0.info" "[init.d/video] Radeon HW Accell. detected: auto-selecting DefaultVideoPlaybackProfile to \"VAAPI Normal\""
                    mm_mythdb_settings_set DefaultVideoPlaybackProfile "VAAPI Normal"
                    ;;
                intel_vaapi)
                    /usr/bin/logger -t minimyth -p "local0.info" "[init.d/video] Intel HW Accell. detected: auto-selecting DefaultVideoPlaybackProfile to \"VAAPI Normal\""
                    mm_mythdb_settings_set DefaultVideoPlaybackProfile "VAAPI Normal"
                    ;;
                vmware)
                    /usr/bin/logger -t minimyth -p "local0.info" "[init.d/video] VMware detected: auto-selecting DefaultVideoPlaybackProfile to \"Slim\""
                    mm_mythdb_settings_set DefaultVideoPlaybackProfile "Slim"
                    ;;
                armsoc)
                    /usr/bin/logger -t minimyth -p "local0.info" "[init.d/video] ArmSOC detected: auto-selecting DefaultVideoPlaybackProfile to \"Slim\""
                    mm_mythdb_settings_set DefaultVideoPlaybackProfile "Slim"
                    ;;
                meson)
                    /usr/bin/logger -t minimyth -p "local0.info" "[init.d/video] Amlogic detected: auto-selecting DefaultVideoPlaybackProfile to \"V4L2 Codecs\""
                    mm_mythdb_settings_set DefaultVideoPlaybackProfile "V4L2 Codecs"
                    ;;
                vc4)
                    /usr/bin/logger -t minimyth -p "local0.info" "[init.d/video] Raspbery PI detected: auto-selecting DefaultVideoPlaybackProfile to \"V4L2 Codecs\""
                    mm_mythdb_settings_set DefaultVideoPlaybackProfile "V4L2 Codecs"
                    ;;
                rockchip)
                    /usr/bin/logger -t minimyth -p "local0.info" "[init.d/video] RockChip detected: auto-selecting DefaultVideoPlaybackProfile to \"Slim\""
                    mm_mythdb_settings_set DefaultVideoPlaybackProfile "Slim"
                    ;;
                sun4i)
                    /usr/bin/logger -t minimyth -p "local0.info" "[init.d/video] AllWinner detected: auto-selecting DefaultVideoPlaybackProfile to \"Slim\""
                    mm_mythdb_settings_set DefaultVideoPlaybackProfile "Slim"
                    ;;
                *)
                    /usr/bin/logger -t minimyth -p "local0.info" "[init.d/video] Unknown video HW: auto-selecting DefaultVideoPlaybackProfile to \"Slim\""
                    mm_mythdb_settings_set DefaultVideoPlaybackProfile "Slim"
                    ;;
            esac


        else

            /usr/bin/logger -t minimyth -p "local0.info" "[init.d/video] DefaultVideoPlaybackProfile forced by minimyth.conf to \"${MM_VIDEO_PLAYBACK_PROFILE}\""
            mm_mythdb_settings_set DefaultVideoPlaybackProfile "${MM_VIDEO_PLAYBACK_PROFILE}"

        fi

    else

        main_menu_jumppoint=`mm_mythdb_jumppoints_get 'Main Menu'`

        if [ "x${main_menu_jumppoint}" = "xAlt+h" ] ; then

            /usr/bin/logger -t minimyth -p "local0.info" "[init.d/video] DefaultVideoPlaybackProfile will be not touched..."

        else

            case "${MM_X_HW_TYPE}" in
                nvidia_vdpau)
                    /usr/bin/logger -t minimyth -p "local0.info" "[init.d/video] Nvidia HW Accell. detected: initial set DefaultVideoPlaybackProfile to \"VDPAU Normal\""
                    mm_mythdb_settings_set DefaultVideoPlaybackProfile "VDPAU Normal"
                    ;;
                nvidia_legacy_vdpau)
                    /usr/bin/logger -t minimyth -p "local0.info" "[init.d/video] Nvidia legacy HW Accell. detected: initial set DefaultVideoPlaybackProfile to \"VDPAU Normal\""
                    mm_mythdb_settings_set DefaultVideoPlaybackProfile "VDPAU Normal"
                    ;;
                radeon_vdpau)
                    /usr/bin/logger -t minimyth -p "local0.info" "[init.d/video] Radeon HW Accell. detected: initial set DefaultVideoPlaybackProfile to \"VDPAU Normal\""
                    mm_mythdb_settings_set DefaultVideoPlaybackProfile "VDPAU Normal"
                    ;;
                radeon_vaapi)
                    /usr/bin/logger -t minimyth -p "local0.info" "[init.d/video] Radeon HW Accell. detected: initial set DefaultVideoPlaybackProfile to \"VAAPI Normal\""
                    mm_mythdb_settings_set DefaultVideoPlaybackProfile "VAAPI Normal"
                    ;;
                intel_vaapi)
                    /usr/bin/logger -t minimyth -p "local0.info" "[init.d/video] Intel HW Accell. detected: initial set DefaultVideoPlaybackProfile to \"VAAPI Normal\""
                    mm_mythdb_settings_set DefaultVideoPlaybackProfile "VAAPI Normal"
                    ;;
                vmware)
                    /usr/bin/logger -t minimyth -p "local0.info" "[init.d/video] VMware detected: initial set DefaultVideoPlaybackProfile to \"Slim\""
                    mm_mythdb_settings_set DefaultVideoPlaybackProfile "Slim"
                    ;;
                armsoc)
                    /usr/bin/logger -t minimyth -p "local0.info" "[init.d/video] ArmSOC detected: initial set DefaultVideoPlaybackProfile to \"Slim\""
                    mm_mythdb_settings_set DefaultVideoPlaybackProfile "Slim"
                    ;;
                meson)
                    /usr/bin/logger -t minimyth -p "local0.info" "[init.d/video] Amlogic detected: initial set DefaultVideoPlaybackProfile to \"V4L2 Codecs\""
                    mm_mythdb_settings_set DefaultVideoPlaybackProfile "V4L2 Codecs"
                    ;;
                vc4)
                    /usr/bin/logger -t minimyth -p "local0.info" "[init.d/video] Raspbery PI detected: initial set DefaultVideoPlaybackProfile to \"V4L2 Codecs\""
                    mm_mythdb_settings_set DefaultVideoPlaybackProfile "V4L2 Codecs"
                    ;;
                rockchip)
                    /usr/bin/logger -t minimyth -p "local0.info" "[init.d/video] RockChip detected: initial set DefaultVideoPlaybackProfile to \"Slim\""
                    mm_mythdb_settings_set DefaultVideoPlaybackProfile "Slim"
                    ;;
                sun4i)
                    /usr/bin/logger -t minimyth -p "local0.info" "[init.d/video] AllWinner detected: initial set DefaultVideoPlaybackProfile to \"Slim\""
                    mm_mythdb_settings_set DefaultVideoPlaybackProfile "Slim"
                    ;;
                *)
                    /usr/bin/logger -t minimyth -p "local0.info" "[init.d/video] Unknown video HW: initial set DefaultVideoPlaybackProfile to \"Slim\""
                    mm_mythdb_settings_set DefaultVideoPlaybackProfile "Slim"
                    ;;
            esac

        fi

    fi

    /usr/bin/logger -s -t minimyth -p "local0.info" "[init.d/video] Started with return code=0..."

    /bin/rm -f /var/lib/init/video.inprogress

    return 0
}

stop() {
    return 0
}

case $1 in
    start) start ;;
    stop)  stop  ;;
esac

exit 0
